using System;
using System.Collections.Generic;
using System.Text;
namespace OPTFleet.OPTFleet {
	public class Entrega{
		private DateTime hora;
		private Encomenda encomenda;
        private Double posx;
        private Double posy;

        public DateTime Hora{
            get{ return hora; }
            set{ hora = value; }
        }

        public Encomenda Encomenda{
            get { return encomenda; }
            set {encomenda = value; }
        }

        public Double PosX
        {
            get { return posx; }
            set { posx = value; }
        }

        public Double PosY
        {
            get { return posy; }
            set { posy = value; }
        }

        public Entrega()
        {
            hora = DateTime.Now;
            encomenda = new Encomenda();
            posx = 0;
            posy = 0;
        }

        public Entrega(DateTime hora, Encomenda encomenda, Double posx,Double posy)
        {
            this.Hora = hora;
            this.Encomenda = encomenda;
            this.PosX = posx;
            this.PosY = posy;
        }

        public class OrdenarPorHora : IComparer<Entrega>
        {
            int IComparer<Entrega>.Compare(Entrega e1, Entrega e2)
            {
                if (e1.Hora.Hour < e2.Hora.Hour)
                    return -1;
                if (e1.Hora.Hour > e2.Hora.Hour)
                    return 1;
                if (e1.Hora.Minute < e2.Hora.Minute)
                    return -1;
                if (e1.Hora.Minute > e2.Hora.Minute)
                    return 1;
                return -1;
            }
        }

        public class OrdenarPorSaida : IComparer<Entrega>
        {
            int IComparer<Entrega>.Compare(Entrega e1, Entrega e2)
            {
                if (e1.PosX == e2.PosX && e1.PosY == e2.PosY)
                    return 0;

                if (e1.PosY + e1.Encomenda.Comprimento > e2.PosY + e2.Encomenda.Comprimento)
                    return -1;
                if (e1.PosY + e1.Encomenda.Comprimento < e2.PosY + e2.Encomenda.Comprimento)
                    return 1;
                if (e1.PosX + e1.Encomenda.Largura > e2.PosY + e2.Encomenda.Largura)
                    return -1;
                if (e1.PosX + e1.Encomenda.Largura < e2.PosY + e2.Encomenda.Largura)
                    return 1;

                return 0;
            }
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("----------------Entrega-----------------");
            sb.Append("\nHora : " + hora.ToString());
            sb.Append("\nPosX: " + posx.ToString());
            sb.Append("\nPosY: " + posy.ToString());
            sb.Append("\n" + encomenda.ToString());
            sb.Append("\n--------------------------------------");

            return sb.ToString();
        }
	}

}
